package com.pengchuang.ACS.admin.boot.controller;

import java.util.Map;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.pengchuang.ACS.admin.boot.entity.SysRoleEntity;
import com.pengchuang.ACS.admin.boot.service.SysRoleService;
import com.pengchuang.ACS.common.utils.PageUtils;
import com.pengchuang.ACS.common.utils.R;



/**
 * 角色表
 *
 * @author pengchaung
 * @email pengshi12138@outlook.com
 * @date 2023-03-14 15:33:20
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/role")
public class SysRoleController {
    // 判断用户层级使用 TODO
    private final SysRoleService sysRoleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysRoleService.queryPage(params);

        return R.ok().put("result", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SysRoleEntity sysRole = sysRoleService.getById(id);

        return R.ok().put("result", sysRole);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SysRoleEntity sysRole){
        if (sysRole.getId() == null) {
            sysRoleService.save(sysRole);
        } else {
            sysRoleService.updateById(sysRole);
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SysRoleEntity sysRole){
		sysRoleService.updateById(sysRole);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestParam Long ids){
		sysRoleService.removeById(ids);

        return R.ok();
    }

}
